Skip to content

fix(context): guard nil local config before context switch#406

Open
Rahulatram321 wants to merge 1 commit into
microcks:masterfrom
Rahulatram321:fix/context-nil-guard
Open

fix(context): guard nil local config before context switch#406
Rahulatram321 wants to merge 1 commit into
microcks:masterfrom
Rahulatram321:fix/context-nil-guard

Conversation

@Rahulatram321
Copy link
Copy Markdown
Contributor

@Rahulatram321 Rahulatram321 commented May 18, 2026

Description

This PR fixes a crash path in the microcks context command when no local config exists yet.

Problem

When running microcks context <context-name> on a fresh machine (or after config cleanup), localCfg can be nil.
The command dereferences localCfg (localCfg.CurrentContext) without a nil guard, which can lead to a nil pointer panic instead of a user-friendly message.

Changes

  • Added a defensive localCfg == nil check in cmd/context.go before first dereference in the context-switch flow.
  • Preserved current behavior for:
    • microcks context (no args): still lists contexts / prints existing output path.
    • microcks context --delete ...: unchanged.

Result

  • No panic when config is missing.
  • Users now get a clear, deterministic error path instead of a runtime crash.

@github-actions
Copy link
Copy Markdown

👋 @Rahulatram321

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

@Vaishnav88sk
Copy link
Copy Markdown

please pass the DCO

Signed-off-by: rahulAtram <rahulatram0226@gmail.com>
@Rahulatram321 Rahulatram321 force-pushed the fix/context-nil-guard branch from 0fb7f62 to 0b50f24 Compare May 23, 2026 19:11
@Rahulatram321
Copy link
Copy Markdown
Contributor Author

please pass the DCO

Thanks for the review and for flagging this.

I’ve updated this PR by rewriting the commit(s) with DCO sign-off and force-pushed the branch.
Each commit now includes:

Signed-off-by: Rahul Atram rahulatram0226@gmail.com

I also kept the scope unchanged to only the intended fix in this PR.
Could you please recheck when the DCO status refreshes? Thanks again.

@Rahulatram321
Copy link
Copy Markdown
Contributor Author

Rahulatram321 commented May 23, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants